package book;

import java.util.ArrayList;
import java.util.List;

public class BookList {
    private static List<Book> books=new ArrayList<>();
    private static List<String> booksName=new ArrayList<>();

    static {
        books.add(new Book("三国演义","罗贯中",66.6,"小说"));
        books.add(new Book("红楼梦","曹雪芹",66.6,"小说"));
        books.add(new Book("水浒传","施耐庵",66.6,"小说"));
        books.add(new Book("西游记","吴承恩",66.6,"小说"));

        booksName.add("三国演义");
        booksName.add("红楼梦");
        booksName.add("水浒传");
        booksName.add("西游记");
    }

    public void add(Book book){
        books.add(book);
        booksName.add(book.getBookName());
    }

    public void del(Book book){
        books.remove(book);
        booksName.remove(book);
    }

    public void displayBooks(){
        for(Book book:books){
            System.out.println(book);
        }
        System.out.println("");
    }

    public boolean contains(String bookName){
        return BookList.booksName.contains(bookName);
    }

    //找到当前书籍在书架位置
    public Book currentBook(String bookName){
        for(Book book:books){
            if(book.getBookName().equals(bookName)){
                return book;
            }
        }
        return null;
    }
}
